﻿
//***********************************************************************
// * Module:   MsjXjCjywfzjlzmsqHandler
// * 作者:  曹荣芝
// * Modified: 2013/5/29
// * Purpose: Definition of the Class MsjXjCjywfzjlzmsqHandler 业务逻辑处理Handler类
// ***********************************************************************/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using XWG.Framework.MSException;
using XWG.Framework.AuthUtility;
using XWG.Framework.AuthEntity;
using XWG.Framework.AuthSPConst;
using XWG.Framework.AuthBLL;
using XWG.JWBST.JWBSTEntity;
using XWG.JWBST.JWBSTSPConst;
using System.Web.Script.Serialization;
using System.Data;
using XWG.Framework.Query;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using XWG.JWBST.JWBSTBLL;
using XWG.Framework;
namespace JWBSTAPP.AjaxServer
{
    /// <summary>
    /// MsjXjCjywfzjlzmsqHandler 的摘要说明
    /// </summary>
    public class MsjXjCjywfzjlzmsqHandler : JWBSTAPP.CommonClass.HttpHandlerBase, System.Web.SessionState.IRequiresSessionState
    {

        #region 添加记录
        /// <summary>
        /// 添加记录
        /// </summary>
        protected void AddRecord()
        {
            HttpContext context = HttpContext.Current;
            context.Response.ContentType = "text/plain";
            ResultModel mResultModel = new ResultModel(); //初始化返回类型
            try
            {
                var mUser = AppOrganizatiOnUserBLL.Load(context.Session["UserID"].ToString());
                MsjXjCjywfzjlzmsq mMsjXjCjywfzjlzmsq = new MsjXjCjywfzjlzmsq();
                mMsjXjCjywfzjlzmsq.Sqid = Guid.NewGuid().ToString(); //主键
                mMsjXjCjywfzjlzmsq.Xm = context.Request.Form["texXm"]; //姓名
                mMsjXjCjywfzjlzmsq.Xb = context.Request.Form["texXb"]; //性别(字典)
                mMsjXjCjywfzjlzmsq.Csrq = context.Request.Form["texCsrq"]; //出生日期
                mMsjXjCjywfzjlzmsq.Cym = context.Request.Form["texCym"]; //曾用名
                mMsjXjCjywfzjlzmsq.Xzz = context.Request.Form["texXzz"]; //现住址
                mMsjXjCjywfzjlzmsq.Hjd = context.Request.Form["texHjd"]; //户籍地
                mMsjXjCjywfzjlzmsq.Gzdw = context.Request.Form["texGzdw"]; //工作单位
                mMsjXjCjywfzjlzmsq.Sspcs = context.Request.Form["texSspcs"]; //所属派出所(字典)
                mMsjXjCjywfzjlzmsq.Sfzh = context.Request.Form["texSfzh"]; //身份证号
                mMsjXjCjywfzjlzmsq.Fsdwlxdh = context.Request.Form["texFsdwlxdh"]; //发送单位联系电话
                mMsjXjCjywfzjlzmsq.Grjl = context.Request.Form["texGrjl"]; //个人简历
                mMsjXjCjywfzjlzmsq.Blyy = context.Request.Form["texBlyy"]; //办理原因
                mMsjXjCjywfzjlzmsq.Slr = context.Request.Form["texSlr"]; //受理人
                mMsjXjCjywfzjlzmsq.Slsj = context.Request.Form["texSlsj"]; //受理时间
                mMsjXjCjywfzjlzmsq.Wtrqz = context.Request.Form["texWtrqz"]; //委托人签字
                mMsjXjCjywfzjlzmsq.Jdjg = context.Request.Form["texJdjg"]; //鉴定结果
                mMsjXjCjywfzjlzmsq.Ldps = context.Request.Form["texLdps"]; //领导批示
                // mMsjXjCjywfzjlzmsq.Zsszzw = context.Request.Form["texZsszzw"]; //左手食指指纹
                // mMsjXjCjywfzjlzmsq.Ysszzw = context.Request.Form["texYsszzw"]; //右手食指指纹
                mMsjXjCjywfzjlzmsq.Cjsj = DateTime.Now.ToString(); //创建时间(2013-05-28 09:13:01)
                mMsjXjCjywfzjlzmsq.Cjr = mUser.UserId; //创建人(人员ID)
                mMsjXjCjywfzjlzmsq.Cjrdw = mUser.OrgnaId; //创建单位(单位ID)
                //mMsjXjCjywfzjlzmsq.Xgr = context.Request.Form["texXgr"]; //修改人(人员ID)
                //mMsjXjCjywfzjlzmsq.Xgrdw = context.Request.Form["texXgrdw"]; //修改人单位(单位ID)
                //mMsjXjCjywfzjlzmsq.Xgsj = context.Request.Form["texXgsj"]; //修改时间(2013-05-28 09:13:01)
                mMsjXjCjywfzjlzmsq.Enabled = "1"; //是否有效（1有效，0无效）
                mMsjXjCjywfzjlzmsq.Movesign = "0"; //是否传输（1已，0未）
                mMsjXjCjywfzjlzmsq.Fsdw = context.Request.Form["texFsdw"]; //发送单位

                mResultModel = MsjXjCjywfzjlzmsqBLL.Insert(mMsjXjCjywfzjlzmsq, context.Session["UserID"], true); //新建操作
                context.Response.Write(JsonConvert.SerializeObject(mResultModel)); //序列化后返回
            }
            catch (Exception ex)
            {
                MSEx.DealErr(ex, "");
                mResultModel.ErrorCode = -9999;
                mResultModel.ISSucceed = false;
                context.Response.Write(JsonConvert.SerializeObject(mResultModel)); //序列化后返回
            }
        }
        #endregion

        #region 删除记录
        /// <summary>
        /// 删除记录
        /// </summary>
        protected void DeleteRecord()
        {

            HttpContext context = HttpContext.Current;
            context.Response.ContentType = "text/plain";
            ResultModel mResultModel = new ResultModel(); //声明返回类型
            try
            {
                string[] arryParamKey = context.Request.Params["id"].ToString().Split(',');
                if (arryParamKey.Length == 0)
                {
                    mResultModel.ErrorCode = -9991;
                    mResultModel.ISSucceed = false;
                    context.Response.Write(JsonConvert.SerializeObject(mResultModel)); //序列化后返回    
                    return;
                }
                MsjXjCjywfzjlzmsq mMsjXjCjywfzjlzmsq = new MsjXjCjywfzjlzmsq();
                foreach (var paramKey in arryParamKey)
                {
                    mResultModel = MsjXjCjywfzjlzmsqBLL.Delete(paramKey, context.Session["UserID"], true); //删除对应的信息
                }
                context.Response.Write(JsonConvert.SerializeObject(mResultModel)); ; //序列化后返回
            }
            catch (Exception ex)
            {
                MSEx.DealErr(ex, ""); //写入异常日志
                mResultModel.ErrorCode = -9999; //-9999代码是系统异常通用代码
                mResultModel.ISSucceed = false; //行为执行失败
                context.Response.Write(JsonConvert.SerializeObject(mResultModel)); //序列化后返回
            }

        }
        #endregion
        #region 修改记录
        /// <summary>
        /// 修改记录
        /// </summary>
        protected void EditRecord()
        {
            HttpContext context = HttpContext.Current;
            context.Response.ContentType = "text/plain";
            ResultModel mResultModel = new ResultModel(); //初始化返回类型
            MsjXjCjywfzjlzmsq mMsjXjCjywfzjlzmsq = new MsjXjCjywfzjlzmsq();

            string paramKey = context.Request.Params["id"];
            try
            {

                if (string.IsNullOrEmpty(paramKey))
                {
                    mResultModel.ErrorCode = -9991;
                    mResultModel.ISSucceed = false;
                    context.Response.Write(JsonConvert.SerializeObject(mResultModel)); //序列化后返回    
                    return;
                }
                mMsjXjCjywfzjlzmsq = MsjXjCjywfzjlzmsqBLL.Load(paramKey); //根据键值获取实体信息
                if (mMsjXjCjywfzjlzmsq != null)
                {
                    var mUser = AppOrganizatiOnUserBLL.Load(context.Session["UserID"].ToString());
                    mMsjXjCjywfzjlzmsq.Xm = context.Request.Form["texXm"]; //姓名
                    mMsjXjCjywfzjlzmsq.Xb = context.Request.Form["texXb"]; //性别(字典)
                    mMsjXjCjywfzjlzmsq.Csrq = context.Request.Form["texCsrq"]; //出生日期
                    mMsjXjCjywfzjlzmsq.Cym = context.Request.Form["texCym"]; //曾用名
                    mMsjXjCjywfzjlzmsq.Xzz = context.Request.Form["texXzz"]; //现住址
                    mMsjXjCjywfzjlzmsq.Hjd = context.Request.Form["texHjd"]; //户籍地
                    mMsjXjCjywfzjlzmsq.Gzdw = context.Request.Form["texGzdw"]; //工作单位
                    mMsjXjCjywfzjlzmsq.Sspcs = context.Request.Form["texSspcs"]; //所属派出所(字典)
                    mMsjXjCjywfzjlzmsq.Sfzh = context.Request.Form["texSfzh"]; //身份证号
                    mMsjXjCjywfzjlzmsq.Fsdwlxdh = context.Request.Form["texFsdwlxdh"]; //发送单位联系电话
                    mMsjXjCjywfzjlzmsq.Grjl = context.Request.Form["texGrjl"]; //个人简历
                    mMsjXjCjywfzjlzmsq.Blyy = context.Request.Form["texBlyy"]; //办理原因
                    mMsjXjCjywfzjlzmsq.Slr = context.Request.Form["texSlr"]; //受理人
                    mMsjXjCjywfzjlzmsq.Slsj = context.Request.Form["texSlsj"]; //受理时间
                    mMsjXjCjywfzjlzmsq.Wtrqz = context.Request.Form["texWtrqz"]; //委托人签字
                    mMsjXjCjywfzjlzmsq.Jdjg = context.Request.Form["texJdjg"]; //鉴定结果
                    mMsjXjCjywfzjlzmsq.Ldps = context.Request.Form["texLdps"]; //领导批示
                    //mMsjXjCjywfzjlzmsq.Zsszzw = context.Request.Form["texZsszzw"]; //左手食指指纹
                    //mMsjXjCjywfzjlzmsq.Ysszzw = context.Request.Form["texYsszzw"]; //右手食指指纹
                    //mMsjXjCjywfzjlzmsq.Cjsj = context.Request.Form["texCjsj"]; //创建时间(2013-05-28 09:13:01)
                    //mMsjXjCjywfzjlzmsq.Cjr = context.Request.Form["texCjr"]; //创建人(人员ID)
                    //mMsjXjCjywfzjlzmsq.Cjrdw = context.Request.Form["texCjrdw"]; //创建单位(单位ID)
                    mMsjXjCjywfzjlzmsq.Xgr = mUser.UserId; //修改人(人员ID)
                    mMsjXjCjywfzjlzmsq.Xgrdw = mUser.OrgnaId; //修改人单位(单位ID)
                    mMsjXjCjywfzjlzmsq.Xgsj = DateTime.Now.ToString(); //修改时间(2013-05-28 09:13:01)
                    mMsjXjCjywfzjlzmsq.Enabled = "1"; //是否有效（1有效，0无效）
                    //mMsjXjCjywfzjlzmsq.Movesign = context.Request.Form["texMovesign"]; //是否传输（1已，0未）
                    mMsjXjCjywfzjlzmsq.Fsdw = context.Request.Form["texFsdw"]; //发送单位

                    mResultModel = MsjXjCjywfzjlzmsqBLL.Update(mMsjXjCjywfzjlzmsq, context.Session["UserID"], true); //新建操作
                }
                else
                {
                    mResultModel.ErrorCode = -9990; //没有获取所需的信息，信息可能已被删除
                    mResultModel.ISSucceed = false;

                }
                context.Response.Write(JsonConvert.SerializeObject(mResultModel)); //序列化后返回
            }
            catch (Exception ex)
            {
                MSEx.DealErr(ex, "");
                mResultModel.ErrorCode = -9999;
                mResultModel.ISSucceed = false;
                context.Response.Write(JsonConvert.SerializeObject(mResultModel)); //序列化后返回
            }
        }
        #endregion

        #region 获取实体记录
        /// <summary>
        /// 获取实体记录
        /// </summary>
        protected void GetModel()
        {
            HttpContext context = HttpContext.Current;
            context.Response.ContentType = "text/plain";
            ResultModel mResultModel = new ResultModel(); //初始化返回类型
            string paramKey = context.Request.Params["id"];
            string json = "";
            try
            {
                MsjXjCjywfzjlzmsq mMsjXjCjywfzjlzmsq = new MsjXjCjywfzjlzmsq(); //声明实体
                if (!string.IsNullOrEmpty(paramKey))
                {
                    mMsjXjCjywfzjlzmsq = MsjXjCjywfzjlzmsqBLL.Load(paramKey); //根据键值获取管理员
                    if (mMsjXjCjywfzjlzmsq != null)
                    {
                        json = JsonConvert.SerializeObject(mMsjXjCjywfzjlzmsq);
                    }
                }
            }
            catch (Exception ex)
            {
                MSEx.DealErr(ex, "");
                mResultModel.ErrorCode = -9990;
                mResultModel.ISSucceed = false;
                json = JsonConvert.SerializeObject(mResultModel);
            }
            context.Response.Write(json);
        }
        #endregion
        #region 获取数据
        /// <summary>
        /// 获取数据记录
        /// </summary>
        protected void QueryRecord()
        {
            TableMessage tm = new TableMessage();
            HearderMessage hm = new HearderMessage();
            List<HearderMessage> list = new List<HearderMessage>();
            HttpContext context = HttpContext.Current;
            context.Response.ContentType = "text/plain";
            string pageSize = context.Request.Form["pageSize"];
            string pageIndex = context.Request.Form["pageIndex"];
            if (String.IsNullOrEmpty(pageSize) || String.IsNullOrEmpty(pageIndex) || !AnyString.IsNumeric(pageSize) || !AnyString.IsNumeric(pageIndex))
                return;
            DataTable dtMsjXjCjywfzjlzmsq = new DataTable();
            int intPageSize = Convert.ToInt32(pageSize);
            int intPageIndex = Convert.ToInt32(pageIndex);
            string name = context.Request.Form["texName"];
            string ID = context.Request.Form["texNo"];
            string work = context.Request.Form["texwork"];
            QueryByPage Q = new QueryByPage();
            QueryInfo qInfo = new QueryInfo();
            SqlConditionList sqllist = new SqlConditionList();
            sqllist.AddLogic(new SqlConditionList.SqlCondition(SqlCompareOper.EQUAL, MsjXjCjywfzjlzmsqConst.Columns.Enabled, "1"), SqlLogicOper.AND_LOGIC);
            if (!string.IsNullOrEmpty(name))
            {
                sqllist.AddLogic(new SqlConditionList.SqlCondition(SqlCompareOper.EQUAL, MsjXjCjywfzjlzmsqConst.Columns.Xm, name), SqlLogicOper.AND_LOGIC);
            }
            if (!string.IsNullOrEmpty(ID))
            {
                sqllist.AddLogic(new SqlConditionList.SqlCondition(SqlCompareOper.EQUAL, MsjXjCjywfzjlzmsqConst.Columns.Sfzh, ID), SqlLogicOper.AND_LOGIC);
            }
            if (!string.IsNullOrEmpty(work))
            {
                sqllist.AddLogic(new SqlConditionList.SqlCondition(SqlCompareOper.LIKE, MsjXjCjywfzjlzmsqConst.Columns.Gzdw, '%' + work + '%'), SqlLogicOper.AND_LOGIC);
            }
            dtMsjXjCjywfzjlzmsq = Q.GetRecordByPage("*", sqllist.ToSql(), "SLSJ", intPageSize, intPageIndex, MsjXjCjywfzjlzmsqConst.TableName, MsjXjCjywfzjlzmsqConst.FieldKey, "Desc").Tables[0];
            if (dtMsjXjCjywfzjlzmsq != null && dtMsjXjCjywfzjlzmsq.Rows.Count > 0)
            {
                for (int i = 0; i < dtMsjXjCjywfzjlzmsq.Columns.Count; i++)
                {
                    hm = new HearderMessage();
                    hm.name = dtMsjXjCjywfzjlzmsq.Columns[i].Caption;
                    list.Add(hm);
                }
                tm.Header = list;
                tm.data = dtMsjXjCjywfzjlzmsq;
                tm.totalCount = Convert.ToString((int)Q.RowCount);
            }
            string json = JsonConvert.SerializeObject(tm);
            context.Response.Write(json);
        }
        #endregion

    }
}


